package org.example.utils;


public class Result<T> {
    // 响应状态码
    private Integer code;

    // 操作结果
    private Boolean success;

    // 提示语
    private String msg;

    // 响应数据
    private T data;

    public static <T> Result<T> success() {
        return new Result<T>(200, true, "操作成功", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(200, true, "操作成功", data);
    }

    public static <T> Result<T> success(String message) {
        return new Result<T>(200, true, message, null);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<T>(200, true, message, data);
    }


    public static <T> Result<T> error() {
        return new Result<T>(500, false, "操作失败！", null);
    }

    public static <T> Result<T> error(T data) {
        return new Result<T>(500, false, "操作失败！", data);
    }

    public static <T> Result<T> error(String message) {
        return new Result<T>(500, false, message, null);
    }

    public static <T> Result<T> error(Integer code) {
        return new Result<T>(code, false, "操作失败！", null);
    }

    public static <T> Result<T> error(String message, T data) {
        return new Result<T>(500, false, message, data);
    }

    public static <T> Result<T> error(Integer code, T data) {
        return new Result<T>(code, false, "操作失败！", data);
    }

    public static <T> Result<T> error(Integer code, String message) {
        return new Result<T>(code, false, message, null);
    }

    public static <T> Result<T> error(Integer code, String message, T data) {
        return new Result<T>(code, false, message, data);
    }


    public Result(Integer code, Boolean success, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.success = success;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public Result<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public Result<T> setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }
}